<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<!-- id不用获取元素就能在js中使用的尝试 -->
		<p id="codeText">let a = 1;</p>
		<button id="copyButton" type="button">复制</button><hr />
		<button type="button" id="paste">粘贴</button>
		<input id="pasteText" type="text" placeholder="可以尝试粘贴" />
	</body>
	<script type="text/javascript">
		console.log(codeText)
		// 复制
		copyButton.onclick = function() {
			navigator.clipboard
				.writeText(codeText.innerText)
				.then(() => alert("复制成功！"))
		}
		// 读取系统剪切板内容进行粘贴
		paste.onclick = function() {
			navigator.clipboard
				.readText()
				.then(text => pasteText.setAttribute("value", text))
		}
		
	</script>
</html>
